// pages/mine/mine.js
var app = getApp()
Page({
  data: {
    userInfo: {},
    user:{},
    // orderItems
    orderItems: [
      {
        typeId: 0,
        name: '全部',
        url: '../myorder/index?currentTab=0',
        imageurl: '../../../assets/icons/quan.png',
      },
      {
        typeId: 1,
        name: '待付款',
        url: '../myorder/index?currentTab=1',
        imageurl: '../../../assets/icons/fu.png',
      },
      {
        typeId: 2,
        name: '待发货',
        url: '../myorder/index?currentTab=2',
        imageurl: '../../../assets/icons/shou1.png',
      },
      {
        typeId: 3,
        name: '待收货',
        url: '../myorder/index?currentTab=3',
        imageurl: '../../../assets/icons/shou.png',
      },
     
     
    ],
  },
  //推出登录
  bindtapTuiChu:function(){
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要退出登录？',
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          //点击确定
          wx.setStorageSync("user", null)
          wx.redirectTo({
            url: '/pages/user/login/index'
          })
        }
      },
    })
   
  },
  //事件处理函数
  toOrder: function (e) {
    console.log(e.currentTarget.dataset.typeid)
    wx.navigateTo({
      url: '../myorder/index?currentTab=' + e.currentTarget.dataset.typeid
    })
  },
  //跳转 收货地址
  bindtapDiZhi: function (e) {    
    wx.navigateTo({
      url: '../addressList/index'
    })
  },
  //跳转 扫描识别
  bindtapShiBie: function (e) {
    wx.navigateTo({
      url: '../../android_1/index'
    })
  },
  onLoad: function () {
    let user = wx.getStorageSync("user")
    console.log(user)
    this.setData({
      user: wx.getStorageSync("user")
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true,
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  }
})
